/*
 * @Author: chenli chenli@kcwl.com
 * @Date: 2023-07-14 16:05:47
 * @LastEditors: chenli 604089679@qq.com
 * @LastEditTime: 2023-07-28 07:13:03
 * @FilePath: \jsnode\typescript\decorator\proDecorator.ts
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
const ProDec: PropertyDecorator = (target, propertyKey) => {
  let myvalue: number = 0;
  Object.defineProperty(target, propertyKey, {
    get() {
      return myvalue + 100;
    },
    set(v) {
      myvalue = v;
      console.log(v);
      
    },
  });
};
const nameDec: PropertyDecorator = (target, propertyKey) => {
  let myvalue: string;
  Object.defineProperty(target, propertyKey, {
    get() {
      return myvalue.toLocaleLowerCase();
    },
    set(v) {
      myvalue = v;
      
    },
  });
};
class Pig {
  @ProDec 
  weight: number;
  @nameDec
  name: string;
  constructor(weight: number, name: string) {
    this.weight = weight;
    this.name = name;
  }
  say(){
    console.log(`${this.name}的体重:`,this.weight);
  }
}
let peiqi = new Pig(90,'PeiQi');
peiqi.say()
